<?php
/**
 * 会员后台控制器
 * 
 * @version $Id: Site.php 290 2012-05-02 14:45:07Z linsir123 $
 */
class controllerSite extends AppController 
{
	/**
	 * @var 模型
	 */
	public $mUser;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		parent::__construct();
		
		///
		$this->mUser = M::user();
	}
	
	/**
	 * 登录
	 */
	public function actionLogin()
	{
		$this->_checkLogin();
		
		///
		if (Request::isPost()) {
			$result = $this->mUser->login();
			$this->ajax($result);
		}
	}
	
	/**
	 * 注册
	 */
	public function actionRegister()
	{
		$this->_checkLogin();
		
		///
		if (Request::isPost()) {
			$con = App::C('Captcha');
			if ($con->check($_POST['captcha'])) 
				$result = $this->mUser->register();
			else 
				$result = '10001|验证码有误';
				
			$this->ajax($result);
		}
	}
	
	/**
	 * 登录面板
	 */
	public function actionPanel()
	{
		$this->_checkLogin();
		
		///
		if ($this->checkCache('user_panel')) 
			return ;
		
		///
		$this->_assignForm('user_panel');
	}
	
	/**
	 * 验证码
	 */
	function actionCaptcha()
	{
		$con = App::C('Captcha');
		$con->display(1, array('bordercolor'=>'#C5C5C5', 'width'=>70, 'height'=>24));
	}
	
	/**
	 * 登出
	 */
	public function actionLogout()
	{
		$flag = $this->mUser->logout();
		
		///
		lpUrl::_r();
	}
	
	/**
	 * 404
	 */
	public function actionMiss() {}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 验证登录状态
	 */
	private function _checkLogin()
	{
		if ($this->mUser->isLogin()) 
			lpUrl::_r('user/main');
	}
	
	/**
	 * 输出表单
	 */
	private function _assignForm($tpl)
	{
		AppView::addJs('jquery.form.js');
		AppView::addJs('jquery.validate.js');
		AppView::addJs('_e35go/plugin.js');
		
		///
		View::display($tpl);
	}
}
